package com.openlogic.common.logic.decision.tree.model;

import java.util.List;

import com.alibaba.fastjson2.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.openlogic.common.logic.decision.tree.model.enums.TreeNodeType;

/**
 * @ClassName: TreeNode
 * @Description: 抽象决策树节点
 * @author weiyongpeng
 * @date 2024年9月25日 上午9:18:13
 */
public class TreeNode {

	/**
	 * 父节点
	 */
	@JsonIgnore
	private TreeNode parentNode;

	/**
	 * 节点类型
	 */
	private String nodeType;
	
	/**
	 * 中文描述
	 */
	private String name;
	
	/**
	 * 表达式
	 */
	private String value;
	
	/**
	 * 参数类型 1(String),2(Integer),3(Date),4(Decimal),5(Boolean)
	 */
	private String varType;
	
	/**
	 * 中文描述
	 */
	private String text;
	
	/**
	 * 是否根节点
	 */
	@JsonProperty("isRoot")
	@JSONField(name="isRoot")
	private Boolean isRoot;
	
    /**
     * 是否叶子节点
     */
	@JsonProperty("isLeaf")
	@JSONField(name="isLeaf")
    private Boolean isLeaf;
    
    /**
     * 下一个节点
     */
    private List<TreeNode> nextNode;
    
    /**
     * 结果
     */
    private Object result;
    
    /**
     * 执行状态
     */
    private Boolean execStatus;
    
    /**
     * 执行时间
     */
    private String startTime;
    
    /**
     * 计算结果
     */
    private Object caclRes;
	
	public void setParentNode(TreeNode parentNode) {
		this.parentNode = parentNode;
	}

	public TreeNode getParentNode() {
		return parentNode;
	}

	public String getNodeType() {
		return nodeType;
	}

	public void setNodeType(String nodeType) {
		this.nodeType = nodeType;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Boolean getIsRoot() {
		return isRoot;
	}

	public void setIsRoot(Boolean isRoot) {
		this.isRoot = isRoot;
	}

	public Boolean getIsLeaf() {
		return isLeaf;
	}

	public void setIsLeaf(Boolean isLeaf) {
		this.isLeaf = isLeaf;
	}

	public String getVarType() {
		return varType;
	}

	public void setVarType(String varType) {
		this.varType = varType;
	}

	public List<TreeNode> getNextNode() {
		return nextNode;
	}

	public void setNextNode(List<TreeNode> nextNode) {
		this.nextNode = nextNode;
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}
	
	public Boolean getExecStatus() {
		return execStatus;
	}

	public void setExecStatus(Boolean execStatus) {
		this.execStatus = execStatus;
	}
	
	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	
	public Object getCaclRes() {
		return caclRes;
	}

	public void setCaclRes(Object caclRes) {
		this.caclRes = caclRes;
	}

	/**
     * 创建叶子节点的树节点
     */
    public static TreeNode buildTreeNode(final String name, final String value, final String text) {
        return buildTreeNode(name, value, text, TreeNodeType.actionNode.getCode(),null,true, false);
    }

    /**
     * 创建参数的树节点
     */
    public static TreeNode buildTreeNode(final String name, final String value, final String text, final List<TreeNode> treeNodes, final boolean isLeaf, final boolean isRoot) {
        return buildTreeNode(name, value, text, TreeNodeType.variableNode.getCode(), treeNodes, isLeaf, isRoot);
    }
    
    /**
     * 创建条件的树节点
     */
    public static TreeNode buildTreeNode(final String name, final String value,final String text, final List<TreeNode> treeNodes) {
        return buildTreeNode(name, value, text, TreeNodeType.conditionNode.getCode(), treeNodes, false, false);
    }

    /**
     * 创建树节点
     */
    public static TreeNode buildTreeNode(final String name, final String value,final String text, final String type, final List<TreeNode> treeNodes,
                                          final boolean isLeaf, final boolean isRoot) {
        TreeNode treeNode = new TreeNode();
        treeNode.setIsLeaf(isLeaf);
        treeNode.setIsRoot(isRoot);
        treeNode.setName(name);
        treeNode.setValue(value);
        treeNode.setText(text);
        treeNode.setNodeType(type);
        treeNode.setNextNode(treeNodes);
        return treeNode;
    }

	@Override
	public String toString() {
		return "TreeNode [parentNode=" + parentNode + ", nodeType=" + nodeType + ", name=" + name + ", value=" + value
				+ ", varType=" + varType + ", text=" + text + ", isRoot=" + isRoot + ", isLeaf=" + isLeaf
				+ ", nextNode=" + nextNode + ", result=" + result + ", execStatus=" + execStatus + ", startTime="
				+ startTime + ", caclRes=" + caclRes + "]";
	}

}